#[macro_export]
macro_rules! impl_model_convert {
    ($from:ty => $to:ty { $($field:ident),* $(,)? }) => {
        impl From<$from> for $to {
            fn from(src: $from) -> Self {
                let mut a = Self::default();
                 $(
                         a.$field = sea_orm::Set(src.$field);
                 )*
                a
            }
        }
    };
}

#[macro_export]
macro_rules! impl_schema_convert {
    ($from:ty => $to:ty { $($field:ident),* $(,)? }) => {
        impl From<$from> for $to {
            fn from(src: $from) -> Self {
                Self{
                    $(
                         $field : src.$field,
                    )*
                }
            }
        }
    };
}

/// 自动 payload 提取宏
/// 这个宏会自动匹配 payload 类型并提取数据
/// 如果类型不匹配，返回适当的错误
#[macro_export]
macro_rules! extract_payload {
    ($payload:expr, $variant:path) => {
        match $payload {
            $variant(data) => Ok(data),
            _ => Err(crate::error::AppError::InvalidPayload(format!(
                "Expected {}",
                stringify!($variant)
            ))),
        }
    };
}

/// 列表转换
#[macro_export]
macro_rules! convert_vec {
    ($v:expr) => {
        $v.into_iter().map(|i| i.into()).collect()
    };
}
